package com.qf.controller;

import com.qf.pojo.Book;
import com.qf.service.BookService;
import com.qf.service.impl.BookServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*

 */
@RestController
@RequestMapping("/book")
@CrossOrigin("*")
public class BookController {
    @Autowired
    private BookServiceImpl bookService;

    @RequestMapping("/add")
    public void addBook(Book book){
        System.out.println(book);
        boolean add = bookService.add(book);
        System.out.println(add?"添加成功":"添加失败");
    }

    @RequestMapping("/queryAll")
    public List<Book> queryAll(){
        return bookService.queryAll();
    }

    @RequestMapping("/remove")
    public void removeBook(int bookId){
        bookService.remove(bookId);
    }

    @RequestMapping("/query")
    public Book query(int bookId){
        return bookService.query(bookId);
    }
    @RequestMapping("/update")
    public void updateBook(Book book){
        bookService.update(book);
    }
}
